home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Containrs / sa / set < prev    next >
Text File  |  1996-04-09  |  6KB  |  145 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Author of H_SET, old abstraction:  Holger Klawitter 
  3. -- Author:  Benedict Gomes <gomes@icsi.berkeley.edu>
  4. -- Copyright (C) 1995, International Computer Science Institute
  5. -- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
  6. -- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
  7. -- LICENSE contained in the file: Sather/Doc/License of the
  8. -- Sather distribution. The license is also available from ICSI,
  9. -- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
  10. -------------------------------------------------------------------
  11. --   SET{E}          :Currently aliased to H_SET{E}
  12. --   $RO_SET{E}      :Abstract read-only sets
  13. --   $SET{E}         :Abstract sets
  14. --   RO_SET_INCL{E}  :Partial class for read-only sets
  15. --   SET_INCL{E}     :Partial class for general sets
  16. --   H_SET{E}        :Concrete set (holger).
  17. --------------------------------------------------------------------------
  18. abstract class $RO_SET{E} < $CONTAINER{E}, $STR is
  19.    -- A read-only set abstraction. No modifying operations are  permitted.
  20.    -- The abstraction consists essential kernel functions (has and elt!) and
  21.    -- a secondary set of useful operations which are defined by RO_SET_INCL
  22.    -- in terms of the kernel functions.
  23.    -- A particular set implementation will normally include RO_SET_INCL
  24.    -- and define the kernel operations as well as any of the other operations
  25.    -- that it can perform in a more efficient manner.
  26.    -- The conventional set operations such as union and intersection
  27.    -- are provided for convenience, but can be easily and more flexibly 
  28.    -- achieved (with control over exactly what type of set is created) 
  29.    -- using set views:
  30.    --  a_union_b ::=  #SET{E}(a.union_view(b);
  31.  
  32.    -- Usage:
  33.    --    See SET{T}
  34.    
  35.    is_empty: BOOL;
  36.     -- Returns 'true' if there is no element in the set.
  37.  
  38.    as_array: ARRAY{E};
  39.    -- Return the elements of the set in an array.
  40.    
  41.    copy: SAME;
  42.    -- Return a copy of the current set.
  43.    
  44.    --              ------ Basic Operations ----------------
  45.    union(a: $RO_SET{E}): $RO_SET{E};
  46.    -- Return a set that is the union of "self" and "a"
  47.  
  48.    diff(a: $RO_SET{E}): $RO_SET{E};
  49.    -- Return a set that is the difference of "self" and "a"
  50.    -- i.e. contains all elements of self except those in "a"
  51.    
  52.    intersection(a: $RO_SET{E}): $RO_SET{E};
  53.    -- Return a set that is the intersection of "self" and "a"
  54.  
  55.    sym_diff(a: $RO_SET{E}): $RO_SET{E};
  56.    -- Return a set that contains all elements that are in either
  57.    -- "self" or "a", but not in both
  58.    
  59.    union_view(a: $RO_SET{E}): $RO_SET{E};
  60.    -- The resulting set behaves as the union of self and "a".
  61.    -- It is a view and changes as the original sets change
  62.  
  63.    diff_view(a: $RO_SET{E}): $RO_SET{E};
  64.    -- The resulting set behaves as the difference between self and "a".
  65.    -- It is a view and changes as the original sets change
  66.  
  67.    intersection_view(a: $RO_SET{E}): $RO_SET{E};
  68.    -- The resulting set behaves as the intersection between self and "a".
  69.    -- It is a view and changes as the original sets change
  70.  
  71.    sym_diff_view(a: $RO_SET{E}): $RO_SET{E};
  72.    -- The resulting set behaves as the symmetric difference bet self and "a".
  73.    -- It is a view and changes as the original sets change
  74.  
  75.    is_subset_of(b: $RO_SET{E}): BOOL;
  76.    -- Return true if self is a subset of "b"
  77.    -- Is defined by a.difference(b) = NULL
  78.  
  79.    equals(s: $RO_SET{E}): BOOL;
  80.    -- Returns true if "s" and self contain the same elements, based on
  81.    -- whatever element equality is used by this set.
  82.  
  83. end;
  84. --------------------------------------------------------------------------
  85. abstract class $SET{E} < $RO_SET{E} is
  86.    -- A set with reference semantics, that may be modified by
  87.    -- inserting and deleting elements
  88.    -- Usage:
  89.    --     See class SET{E}
  90.  
  91.    insert(e:E);
  92.    -- Inserts the element 'e' into the set. Do nothing if "e" is present
  93.  
  94.    delete(e: E);
  95.    -- Deletes the element equal to 'e' from the set
  96.  
  97.    has(e:E): BOOL;
  98.     -- Returns 'true' if 'e' is in the set.
  99.  
  100.    elt!: E;
  101.    -- Yields all elements of the set in arbitrary order
  102.  
  103.    copy: SAME;
  104.    -- Return a copy of the current set.
  105.    
  106.    clear;
  107.    -- Delete all elements
  108.  
  109.    copy_from(s: $CONTAINER{E});
  110.  
  111.    union(a: $RO_SET{E}): $SET{E};
  112.    -- Return a set that is the union of "self" and "a"
  113.  
  114.    diff(a: $RO_SET{E}): $SET{E};
  115.    -- Return a set that is the difference of "self" and "a"
  116.    -- i.e. contains all elements of self except those in "a"
  117.    
  118.    intersection(a: $RO_SET{E}): $SET{E};
  119.    -- Return a set that is the intersection of "self" and "a"
  120.  
  121.    sym_diff(a: $RO_SET{E}): $SET{E};
  122.    -- Return a set that contains all elements that are in either
  123.    -- "self" or "a", but not in both
  124.    
  125.    -- The following operations actually modify "self", transforming it
  126.    -- into the desired result.
  127.    to_union(a: $SET{E});
  128.    -- Transform self into the union of self and a consisting 
  129.    -- of elements present in either self or a
  130.  
  131.    to_intersection(a: $SET{E});
  132.    -- Transform self into the intersection of self and a,
  133.    -- consisting of only those elements present in self and a
  134.  
  135.    to_diff(a: $SET{E});
  136.    -- Transform self into the difference between self and a,
  137.    -- elements present in self but not in a
  138.  
  139.    to_sym_diff(a: $SET{E});
  140.    -- Transform self to contain only elements present in self or a, but
  141.    -- not in both
  142.  
  143. end; -- $SET{E}
  144. --------------------------------------------------------------------------
  145.